home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / nacs.arc / NACSLOOP.C < prev    next >
Text File  |  1989-09-26  |  4KB  |  140 lines

  1. /* NACSLOOP.C
  2.  *
  3.  *
  4.  * ARGUMENT:
  5.  *    None
  6.  *
  7.  * DESRCIPTION:
  8.  *    This sample program provides the capability to transmit and receive
  9.  *    characters via NASI and NACS.
  10.  *
  11.  * RETURNS:
  12.  *        None
  13.  * 
  14.  * AUTHOR:
  15.  *        Kamy Rahimi  17-JUN-1989  14:45:24.94
  16.  *        Copyright (C) 1989 Novell, Inc. CPD
  17.  * 
  18.  *
  19.  * MODIFICATIONS:
  20.  *
  21.  */
  22. #include <stdio.h>
  23. #include <conio.h>
  24. #include <memory.h>
  25. #include <process.h>
  26.  
  27. #define ON 1
  28. #define OFF 0
  29. #define ESC 27
  30. #define MIN_NAME_LEN 8
  31. #define MAX_NAME_LEN 14
  32.  
  33. typedef struct {
  34.     int    BuffLength;    
  35.     char    ServerName[MIN_NAME_LEN];
  36.     char    GeneralName[MIN_NAME_LEN];
  37.     char    SpecificName[MAX_NAME_LEN];
  38.     } NACSPort;
  39.  
  40. typedef struct {
  41.     int    length;                /* length of request buffer */
  42.     int    portID;                /* logical port ID */
  43.     int    RXDataRate;            /* RX data rate */
  44.     int    RXWordLength;        /* RX word length */
  45.     int    RXStopBit;             /* RX stop bit */
  46.     int    RXParity;             /* RX parity */
  47.     int    TXDataRate;            /* TX data rate */
  48.     int    TXWordLength;        /* TX word length */
  49.     int    TXStopBit;             /* TX stop bit */
  50.     int    TXParity;            /* TX parity */
  51.     int    dtr;                    /* DTR */
  52.     int    rts;                    /* RTS */
  53.     } PortConfig;
  54.  
  55. extern int    IsNasiLoaded (void);
  56. extern char    AllocateCircuit (void);
  57. extern NACSPort *QueryName (char, NACSPort far *);
  58. extern int    VirtualCircuitConfig (int, PortConfig far *,int);
  59. extern int    InitVirtualCircuit (char, NACSPort far *);
  60. extern int    RXStatus (char);
  61. extern int    NASIRead (char, char *, int);
  62. extern int    TXStatus (char);
  63. extern int    NASIWrite (char, char *, int);
  64. extern int    NASIDisconnect (int);
  65.  
  66. #ifdef    LINT_ARGS
  67.  void main(void);
  68. #endif
  69.  
  70. void main()
  71. {
  72.     char key;
  73.     char VCircuitNum;
  74.     NACSPort *dport;
  75.     PortConfig *config;
  76.     int i, NumOfChars;
  77.     char ReceiveBuff[512];
  78.     char TransmitBuff[512];
  79.  
  80.     printf("\nNACSLOOP.EXE - A Simple NASI Application\n");
  81.     printf("Copyright (C) 1989 Novell, Inc. CPD\n");
  82.     printf("\nLoops one character at a time through NACS. Press ESC to exit.\n\n");
  83.  
  84.      if (!IsNasiLoaded()) {
  85.         printf("NASI is NOT loaded, load it and try again.\n\n");
  86.         exit(1);
  87.     }
  88.     if ( (VCircuitNum=AllocateCircuit()) < 0 ){
  89.         printf("No Virtual Circuit Available.\n");
  90.         exit(2);
  91.     }
  92.  
  93.     dport->BuffLength = sizeof(NACSPort) - sizeof(int);
  94.     memcpy (dport->ServerName, "BAY-NACS",    MIN_NAME_LEN );
  95.     memcpy (dport->GeneralName, "????????", MIN_NAME_LEN );
  96.     memcpy (dport->SpecificName, "??????????????", MAX_NAME_LEN );
  97.  
  98.     if ( (dport=QueryName(VCircuitNum,(NACSPort far *)dport)) < 0 ){
  99.         printf("Error - No Record Found.\n");
  100.         exit(3);
  101.     }
  102.  
  103.     printf("\nServer Name\tGeneral Name\tSpecific Name");
  104.     printf("\n-----------\t------------\t-------------");
  105.     printf("\n%.8s\t%.8s\t%.14s\n\n",
  106.         dport->ServerName, dport->GeneralName, dport->SpecificName);
  107.  
  108.     VirtualCircuitConfig (VCircuitNum, (PortConfig far *)config, 1);
  109.  
  110.     /* Change the configuration if you need to */
  111.  
  112.     config->length = 0xC;            /* length of request buffer */
  113.     config->portID = VCircuitNum;
  114.     config->RXDataRate = 10;        /* RX data rate - 2400 */
  115.     config->TXDataRate = 10;        /* TX data rate - 2400 */
  116.     config->dtr = ON;                    /* DTR */
  117.     config->rts = ON;                    /* RTS */
  118.  
  119.     VirtualCircuitConfig (VCircuitNum, (PortConfig far *)config, 0);
  120.  
  121.     do {
  122.     } while ( InitVirtualCircuit (VCircuitNum, (NACSPort far *)dport) == -1 );
  123.  
  124.     for (key=0; key!=ESC; ) {
  125.         if (RXStatus (VCircuitNum) >= 0){
  126.             if ( (NumOfChars=NASIRead(VCircuitNum, ReceiveBuff, 1)) != -1 )     /* one char at a time */
  127.                 for (i=0; i<NumOfChars; i++)
  128.                     putchar ( (char)ReceiveBuff[i] );
  129.         }
  130.         if ( kbhit() && (key=(char)getch())!=ESC ){
  131.             memcpy ((char *)TransmitBuff, (char *)&key, 1);
  132.                 if (TXStatus (VCircuitNum) >= 0)
  133.                     NASIWrite (VCircuitNum, TransmitBuff, 1);
  134.         }
  135.     }
  136.  
  137.     NASIDisconnect (VCircuitNum);    
  138.     exit(0);
  139. }
  140.